package org.atlantis.uzw.utils;

import java.security.SecureRandom;
import java.util.UUID;

/**
 * 唯一性ID生成工具类
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">李曦</a><br/>
 *         Created at: 2013-7-26 下午2:45:41
 */
public class Identities {

	private static final SecureRandom random = new SecureRandom();

	/**
	 * JDK自带的UUID算法，无-分割
	 * 
	 * @return
	 */
	public static String uuid() {
		return UUID.randomUUID().toString().replaceAll("-", "").toLowerCase();
	}

	/**
	 * 使用SecureRandom随机生成Long
	 * 
	 * @return
	 */
	public static long randomLong() {
		return Math.abs(random.nextLong());
	}

	/**
	 * 基于Base62编码的SecureRandom随机生成bytes
	 * 
	 * @param length
	 * @return
	 */
	public static String randomBase62(int length) {
		byte[] randomBytes = new byte[length];
		random.nextBytes(randomBytes);
		return Encodes.encodeBase62(randomBytes);
	}
}
